using ElasticSearchRealize.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ElasticSearchRealize.QueryProvider
{
    /// <summary>
    /// 索引操作提供者
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public interface IIndexProvider<TEntity> where TEntity : class, IDocumentIndexIdentity
    {
        /// <summary>
        /// Creates the index.
        /// </summary>
        /// <param name="indexName">Name of the index.</param>
        void CreateIndex(string indexName);

        /// <summary>
        /// 更新索引的类型字段映射
        /// </summary>
        /// <param name="indexName">索引名称</param>
        /// <exception cref="Exception">更新索引映射失败</exception>
        void UpdateIndexMapping(string indexName);

        /// <summary>
        /// 批量添加文档到ES
        /// </summary>
        /// <param name="documents">文档集合</param>
        /// <param name="refreshOnCompleted">强制在完成添加文档之后刷新索引，除非有足够的理由，否则请使用默认false</param>
        void AddDocuments(IEnumerable<TEntity> documents, bool refreshOnCompleted = false);

        /// <summary>
        /// 检索一份文档
        /// </summary>
        /// <param name="indexName">索引名称</param>
        /// <param name="documentId">文档Id</param>
        /// <returns></returns>
        Task<TEntity> GetDocumentAsync(string indexName, string documentId);

        /// <summary>
        /// 删除一个文档
        /// </summary>
        /// <param name="indexName">索引名称</param>
        /// <param name="documentId">文档Id</param>
        Task DeleteDocumentAsync(string indexName, string documentId);

        /// <summary>
        /// 删除一个索引
        /// </summary>
        /// <param name="indexName">索引名称</param>
        /// <param name="documentId">文档Id</param>
        bool DeleteDocument(string indexName);

        /// <summary>
        /// 复制索引数据到新索引
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="copyIndex"></param>
        /// <returns></returns>
        bool CopyIndexData(string indexName, string copyIndex, int numberOfReplicas);

        /// <summary>
        /// 添加文档
        /// </summary>
        void AddDocument(TEntity document);
    }
}
